/*
 * ViewConnectionsCommand.java
 *
 * Created on October 3, 2007, 12:23 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package drb;

import java.sql.*;

/**
 *
 * @author Asger
 */
public class ViewConnectionsCommand extends Command {
    
    /** Creates a new instance of ViewConnectionsCommand */
    public ViewConnectionsCommand() {
    }
    
    public void execute() throws SQLException
    {
        long today = getTodayTime();
        long tomorrow = today + ONE_DAY;
        String sql = "SELECT * FROM connections WHERE departure>="+today+" AND arrival<="+tomorrow;
        ResultSet result = connection.createStatement().executeQuery(sql);
        
        int numResults = 0;
        while (result.next()) {
            String from = result.getString("from_name");
            String to = result.getString("to_name");
            String departure = formattedDateTime(result.getLong("departure"));
            String arrival = formattedTime(result.getLong("arrival"));
            
            System.out.println(from + " to " + to + " at " + departure + " - " + arrival);
            numResults++;
        }
        
        if (numResults == 0) {
            System.out.println("No connections found. Try applying the schedule.");
        }
    }
}
